package com.longge;

public class GuessGame {

    public int guessNumber(int n) {
        int left = 0;
        int right = n;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (guess(mid) > 0) {
                left = mid + 1;
            } else if (guess(mid) < 0) {
                right = mid - 1;
            } else if (guess(mid) == 0) {
                return mid;
            }
        }
        return 0;
    }


    public int guess(int x) {
        return x;
    }
}
